<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@page import="com.liuya.safe.policy.handler.QueryDesignHandler" %>
<%@page import="com.liuya.db.sql.xml.QueryType" %>
<%@page import="com.liuya.db.sql.xml.Table" %>
<%@page import="com.liuya.db.sql.xml.Column" %>
<%@page import="com.liuya.common.StringUtil" %>
<%@page import="java.util.List" %>
<%@page import="java.util.Iterator" %>
<%@page import="java.util.Map" %>
<%@page import="java.util.HashMap" %>
<%@ page import="com.liuya.common.I18N" %>

<%
    I18N i18n = I18N.getWebInstance(request);
    QueryType query = (QueryType) request.getAttribute("queryType");
    String id = request.getParameter("id");

    Column[] columns = query.getQueryTypeSequence().getOrderBy().getColumn();
    Map aliasNameMap = new HashMap();
    Table[] tables = query.getQueryTypeSequence().getFrom().getTable();
    for (int i = 0; i < tables.length; i++) {
        aliasNameMap.put(tables[i].getAlias(), tables[i].getName());
    }
%>

<table class="ralaTable">
    <tr>
        <th><%=i18n.say("Table")%>[<%=i18n.say("alias")%>]</th>
        <th><%=i18n.say("Column")%>
        </th>
        <th><%=i18n.say("Order")%>
        </th>
        <th><%=i18n.say("Action")%>
            <a href="javascript:addOrderColumn()" title="Add"><img src="/style/images/add.gif"/></a></th>
    </tr>
    <% for (int i = 0; i < columns.length; i++) {
        Column column = columns[i];
        String alias = column.getTableAlias();
        String tableName = (String) aliasNameMap.get(alias);
        String name = column.getName();
        String displayName = tableName + "[" + alias + "]";
        String order = column.getOrder().toString();
    %>
    <tr>
        <td><%=displayName%>
        </td>
        <td><%=name%>
        </td>
        <td><%=order %>
        </td>
        <td><a href="javascript:moveOrderColumn('top', '<%=alias %>','<%=name %>');" title="Top"><img
                src="/style/images/top.gif"/></a>
            <a href="javascript:moveOrderColumn('up', '<%=alias %>','<%=name %>');" title="Up"><img
                    src="/style/images/up.gif"/></a>
            <a href="javascript:moveOrderColumn('down', '<%=alias %>','<%=name %>');" title="Down"><img
                    src="/style/images/down.gif"/></a>
            <a href="javascript:moveOrderColumn('bottom', '<%=alias %>','<%=name %>');" title="Bottom"><img
                    src="/style/images/bottom.gif"/></a>
            <a href="javascript:editOrderColumn(<%=i %>, '<%=alias %>','<%=name %>');" title="Edit"><img
                    src="/style/images/edit.gif"/></a>
            <a href="javascript:deleteOrderColumn('<%=alias %>','<%=name %>');" title="Delete"><img
                    src="/style/images/delete.gif"/></a>
        </td>
    </tr>
    <%
        }
    %>
    <tr>
    </tr>
</table>


<script type="text/javascript">
    jQuery(document).ready(function () {

    });


</script>